/*********************************************************************
* File: CommunicationSampleAgent.cpp
*
* Implements the communication API sample. 
*
* \author Instituto Superior Tecnico de Lisboa, Portugal
* \author Technical University of Lisbon, Portugal
* 
* \author Agentes Autonomos e Sistemas Multiagente
* \author Autonomous Agents and Multiagent Systems
* 
* \version	1.0
* \date		2006/2007
*********************************************************************/
#include "CommunicationSampleAgent.h"
using namespace agents::samples;

#include "../../util/debug.h"
using namespace util;

#pragma warning( disable : 4482 )  // Disable warning messages


CommunicationSampleAgent::CommunicationSampleAgent(edict_t *enity, int team, int model)
:Agent(enity, team, model)
{	
}

CommunicationSampleAgent::~CommunicationSampleAgent(){}

void CommunicationSampleAgent::think()
{	
	checkRadioCommands();

	char msgBuffer[512];
	ICommunication::MessageRecord record;

	if(getCommunication().receiveMsg(ICommunication::SayMessages::sayMsg, &record))
	{
		sprintf(msgBuffer, "%s: Received chat message from '%s': '%s' \n", getName(), record.sender.name, record.msg);
		util::debug::printToServer(msgBuffer);
	}
	else if(getCommunication().receiveMsg(ICommunication::SayMessages::sayTeamMsg, &record))
	{
		sprintf(msgBuffer, "%s: Received team chat message from '%s': '%s' \n", getName(), record.sender.name, record.msg);
		util::debug::printToServer(msgBuffer);
	}
	else if(getCommunication().receiveMsg(ICommunication::SayMessages::sayDeadMsg, &record))
	{
		sprintf(msgBuffer, "%s: Received dead chat message from '%s': '%s' \n", getName(), record.sender.name, record.msg);
		util::debug::printToServer(msgBuffer);
	}
}

void CommunicationSampleAgent::checkRadioCommands()
{
	char msgBuffer[512];

	ICommunication::RadioMessageRecord record;
	if(!getCommunication().receiveRadioMsg(&record))
		return;

	switch (record.msg)
	{
	case ICommunication::RadioMessages::affirmative:
			sprintf(msgBuffer, "%s: Received 'affirmative' RADIO command! \n", getName());
			util::debug::printToServer(msgBuffer);
			break;
	case ICommunication::RadioMessages::coverMe:
			sprintf(msgBuffer, "%s: Received 'cover me' RADIO command! \n", getName());
			util::debug::printToServer(msgBuffer);
			getCommunication().sendRadioMessage(ICommunication::RadioMessages::affirmative);
			break;
	case ICommunication::RadioMessages::enemyDown:
			sprintf(msgBuffer, "%s: Received 'enemy down' RADIO command! \n", getName());
			util::debug::printToServer(msgBuffer);
			break;
	case ICommunication::RadioMessages::enemySpotted:
			sprintf(msgBuffer, "%s: Received 'enemy spotted' RADIO command! \n", getName());
			util::debug::printToServer(msgBuffer);
			break;
	case ICommunication::RadioMessages::fallBack:
			sprintf(msgBuffer, "%s: Received 'fall back' RADIO command! \n", getName());
			util::debug::printToServer(msgBuffer);
			break;
	case ICommunication::RadioMessages::followMe:
			sprintf(msgBuffer, "%s: Received 'follow me' RADIO command! \n", getName());
			util::debug::printToServer(msgBuffer);
			break;
	case ICommunication::RadioMessages::getInPosition:
			sprintf(msgBuffer, "%s: Received 'get in position' RADIO command! \n", getName());
			util::debug::printToServer(msgBuffer);
			break;
	case ICommunication::RadioMessages::goGoGo:
			sprintf(msgBuffer, "%s: Received 'go go go' RADIO command! \n", getName());
			util::debug::printToServer(msgBuffer);
			break;
	case ICommunication::RadioMessages::holdPosition:
			sprintf(msgBuffer, "%s: Received 'hold position' RADIO command! \n", getName());
			util::debug::printToServer(msgBuffer);
			break;
	case ICommunication::RadioMessages::imInPosition:
			sprintf(msgBuffer, "%s: Received 'I'm in position' RADIO command! \n", getName());
			util::debug::printToServer(msgBuffer);
			break;
	case ICommunication::RadioMessages::needBackup:
			sprintf(msgBuffer, "%s: Received 'need backup' RADIO command! \n", getName());
			util::debug::printToServer(msgBuffer);
			break;
	case ICommunication::RadioMessages::negative:
			sprintf(msgBuffer, "%s: Received 'negative' RADIO command! \n", getName());
			util::debug::printToServer(msgBuffer);
			break;
	case ICommunication::RadioMessages::regroupTeam:
			sprintf(msgBuffer, "%s: Received 'regroup team' RADIO command! \n", getName());
			util::debug::printToServer(msgBuffer);
			break;
	case ICommunication::RadioMessages::reportingIn:
			sprintf(msgBuffer, "%s: Received 'reporting in' RADIO command! \n", getName());
			util::debug::printToServer(msgBuffer);
			break;
	case ICommunication::RadioMessages::reportTeam:
			sprintf(msgBuffer, "%s: Received 'report team' RADIO command! \n", getName());
			util::debug::printToServer(msgBuffer);
			break;
	case ICommunication::RadioMessages::sectorClear:
			sprintf(msgBuffer, "%s: Received 'sector clear' RADIO command! \n", getName());
			util::debug::printToServer(msgBuffer);
			break;
	case ICommunication::RadioMessages::shesGonnaBlow:
			sprintf(msgBuffer, "%s: Received 'she's gonna blow' RADIO command! \n", getName());
			util::debug::printToServer(msgBuffer);
			break;
	case ICommunication::RadioMessages::stickTogether:
			sprintf(msgBuffer, "%s: Received 'stick togheter' RADIO command! \n", getName());
			util::debug::printToServer(msgBuffer);
			break;
	case ICommunication::RadioMessages::stormTheFront:
			sprintf(msgBuffer, "%s: Received 'storm the front' RADIO command! \n", getName());
			util::debug::printToServer(msgBuffer);
			break;
	case ICommunication::RadioMessages::takingFire:
			sprintf(msgBuffer, "%s: Received 'taking fire' RADIO command! \n", getName());
			util::debug::printToServer(msgBuffer);
			break;
	case ICommunication::RadioMessages::youTakePoint:
			sprintf(msgBuffer, "%s: Received 'you take point' RADIO command! \n", getName());
			util::debug::printToServer(msgBuffer);
			break;
	}
}

